#!/bin/bash
#  v 1.0
# 修正原check_total_proc 無法顯示 Poformanin Data

warning=$1
critical=$2
work_dir="/usr/lib/nagios/plugins"
work_cmd="check_procs"
get_value=`$work_dir/$work_cmd`

if [  -f $get_value ]; then
	echo "Con't Found Nagios plugins $work_cmd"
	exit 3
fi

Pdata=(`echo $get_value |awk -F ' ' '{print $2 $3}' | sed s/\:/\ /g`)

if ([ -z "$warning" ] || [ -z "$critical" ]);then
	echo "Must Keyin format for $0 Warning Critical"
	exit 3
fi

if [ "$warning" -gt "$critical" ]; then
	echo "warning con't over critical."
	exit 3
fi

if ([ ! -z "$critical" ] && [ ${Pdata[1]} -gt "$critical" ]);then
	echo Critical Total Processes: ${Pdata[1]} \| Total\ Processes\=\ ${Pdata[1]}\;\;\;
	exit 2
fi

if ([ ! -z "$warning" ] && [ ${Pdata[1]} -gt "$warning" ]);then
	echo Warning Total Processes: ${Pdata[1]} \| Total\ Processes\=\ ${Pdata[1]}\;\;\;
	exit 1
fi

echo $get_value \| Total\ Processes\=\ ${Pdata[1]}\;\;\;
exit 0